﻿@model sBlog.Net.Domain.Entities.UserEntity
<script type="text/javascript">
    $(document).ready(function () {
        $('#newBlash').hide();
        $('#uploadAvatar').hide();
        $('#uploadCover').hide();

        $("#Splash").keyup(function (e) {
            if (e.keyCode == 13) {
                updateBlash();
                return false;
            }
        });

        $("#Splash").keydown(function (e) {
            if (e.keyCode == 13) {
                updateBlash();
                return false;
            }
        });
    });

    function follow() {
        var noCache = new Date().toString();
        $.getJSON('@Url.Content("~/Author/follow?followerUserId=" + @Model.UserID)', { noCache: noCache }, function (data) {
            $("#textFollow").attr("src", data).fadeIn('normal');
        });
    }

    function editBlash() {
        $('#newBlash').show();
        $('#orginalBlash').hide();
    }

    function cancel() {
        $('#newBlash').hide();
        $('#orginalBlash').show();
    }

    function updateBlash() {
        var Blash = document.getElementById("Splash").value;
        var noCache = new Date().toString();

        $.getJSON('/Author/updateBlash?blash=' + Blash, { noCache: noCache }, function (data) {
            var newBlash = document.getElementById("orginalBlash");
            newBlash.innerHTML = data;
        });

        cancel();
    }

    function editAvatar() {
        $('#editAvatar').hide();
        $('#uploadAvatar').show();
    }

    $(window).load(
    function () {
        $("#dvUpload").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': 'Browser Image',
            'script': '/Home/UploadUserAvatar',
            'onComplete': function (event, queueID, fileObj, response, data) {
                updateAvatar(response);
            },
            'folder': '/UploadThumbs',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg',
            'multi': false,
            'auto': true
        });

        $("#dvUploadCover").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': 'Browser Image',
            'script': '/Home/UploadUserCover',
            'onComplete': function (event, queueID, fileObj, response, data) {
                updateCover(response);
            },
            'folder': '/UploadUserCover',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg',
            'multi': false,
            'auto': true
        });
    }
    );

    function updateAvatar(avatar) {
        var noCache = new Date().toString();
        $.getJSON('/Author/updateAvatar?Avatar=' + avatar, { noCache: noCache }, function (data) {
            var imgUrl = data;
            $("#avatar").attr("src", imgUrl).fadeIn('normal');
        });

        cancelEditAvatar();
    }

    function updateCover(cover) {
        var noCache = new Date().toString();
        $.getJSON('/Author/updateCover?Cover=' + cover, { noCache: noCache }, function (data) {
            var imgUrlCover = "http://s1.img.yan.vn/Mlog/UploadUserCover/1000x280_" + data;
            $("#cover").attr("src", imgUrlCover).fadeIn('normal');
        });

        cancelEditCover();
    }

    function cancelEditAvatar() {
        $('#editAvatar').show();
        $('#uploadAvatar').hide();
    }

    function cancelEditCover() {
        $('#editCover').show();
        $('#uploadCover').hide();
    }

    function editCover() {
        $('#editCover').hide();
        $('#uploadCover').show();
    }
           
</script>
<div class="userProfile">
    <div class="blash">
        <div class="left">
            <img src="@Url.Content("~/Content/Images/MlogThem/splash-1.png")" width="41" height="27" alt="blash"/>
        </div>
        <div class="middle">
            <div id="orginalBlash">@Model.Splash</div>
            <span id="newBlash">@Html.TextBoxFor(model => model.Splash, new { Style = "width:700px;" })
                <span class="urlControls">
                    <input type="button" id="btnUpdate" onclick="return updateBlash();" value="ok" />&nbsp;<input
                        type="button" id="btnCancel" value="cancel" onclick="return cancel();" />
                </span></span>
        </div>
        <div class="right">
            <img src="@Url.Content("~/Content/Images/MlogThem/splash-2.png")" width="41" height="27" alt="blash"/>&nbsp;
            @if (User.Identity.IsAuthenticated)
            {
                if (Membership.GetUser().UserName.Equals(@Model.UserName))
                { 
                <img src="@Url.Content("~/Content/Images/MlogThem/compose-icon-homeuser.png")"onclick="return editBlash();" style="cursor: pointer;" width="16" height="16" alt="editblash"/>
                }
            }
        </div>
    </div>
    <div class="userInfo">
        <div>
            @if (@Model.Cover == null)
            { 
                <img src="@Url.Content("~/Content/Images/MlogThem/cover.jpg")" width="1000" height="280" alt="blash"/>
            }
            else
            {
                <img id="cover" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadUserCover/1000x280_" + Model.Cover)" width="1000" height="280" alt="blash"/>
            }
            @if (User.Identity.IsAuthenticated)
            {
                if (Membership.GetUser().UserName.Equals(@Model.UserName))
                { 
                <div id="editCover" class="editCover">
                    <a href="javascript: editCover()">edit cover (1000x280)</a>
                </div>
                <div id="uploadCover" class="editCover">
                    <div id="dvUploadCover">
                        @Html.Hidden("Cover")
                    </div>
                </div>
                }
            }
        </div>
        <div class="infomation">
            <div class="avatar">
                <img id="avatar" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadUserAvatar/" + Model.Avatar)" class="imgAvatar" style="border: 4px solid #FFFFFF;" width="150" height="150" alt="user avatar"/><br />
                @if (User.Identity.IsAuthenticated)
                {
                    if (Membership.GetUser().UserName.Equals(@Model.UserName))
                    { 
                    <div id="editAvatar" class="editAvatar">
                        <a href="javascript: editAvatar()">edit avatar (150x150)</a>
                    </div>
                    <div id="uploadAvatar" class="editAvatar">
                        <div id="dvUpload">
                            @Html.Hidden("PostAvatar")
                        </div>
                    </div>
                    }
                }
            </div>
            <div class="text">
                <table style="width: 100%;">
                    <tr>
                        <td>
                            <span class="displayName"><a href="/tac-gia/@Model.UserName">@Model.UserDisplayName</a>
                            </span>
                            <br />
                            @Model.JobDescription<br />
                            @if (@Model.Birthday.ToString() != null)
                            {                                 
                                @Html.Label(Convert.ToDateTime(@Model.Birthday).ToString("dd/MM/yyyy"))
                            }
                            <br />
                        </td>
                        <td>
                            Nơi sống<br />
                            <span class="title">@Model.City</span>
                        </td>
                        <td>
                            Làm việc tại<br />
                            <span class="title">@Model.WorkAt</span>
                        </td>
                        <td>
                            Tình trạng<br />
                            @if (Model.Married)
                            { 
                                <span class="title">@Html.Raw("Đã kết hôn")</span>
                            }
                            else
                            { 
                                <span class="title">@Html.Raw("Độc thân")</span>
                            }
                        </td>
                        <td style="width: 100px;">
                            <img src="@Url.Content("~/Content/Images/MlogThem/heart-follow.png")" width="19" height="15" alt="LikeCount"/>&nbsp;
                            <span class="title">
                                @Convert.ToInt32(@Model.TotalLikePost).ToString("#,##0")
                            </span>
                            <br />
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Following:&nbsp;<span class="title">
                                @Convert.ToInt32(@Model.TotalFollowing).ToString("#,##0")
                            </span>&nbsp;&nbsp;Follower:&nbsp; <span class="title">
                                @Convert.ToInt32(@Model.TotalFollower).ToString("#,##0")
                            </span>
                            <br />
                        </td>
                        <td>
                            Post:<br />
                            <span class="title">
                                @Convert.ToInt32(@Model.TotalPost).ToString("#,##0")
                            </span>
                        </td>
                        <td>
                            Tổng lượt xem bài:<br />
                            <span class="title">
                                @Convert.ToInt32(@Model.TotalViewPost).ToString("#,##0")
                            </span>
                        </td>
                        <td>
                            @if (User.Identity.IsAuthenticated)
                            {
                                if (Membership.GetUser().UserName.Equals(@Model.UserName))
                                { 
                                <a href="/trang-chu/@Model.UserName">
                                    <img src="@Url.Content("~/Content/Images/MlogThem/house-user-active.png")" width="22" height="21" alt="Home user" /></a>
                                @:&nbsp;
                                    <a href="/admin/post/add">
                                        <img src="@Url.Content("~/Content/Images/MlogThem/compose-icon-homeuser.png")" width="16" height="16" alt="Home user" /></a>
                                @:&nbsp;
                                }
                                if (!Membership.GetUser().UserName.Equals(@Model.UserName))
                                {
                                <img src="@ViewData["FollowText"]" id="textFollow" width="19" height="20" alt="Home user" onclick="return follow();" style="cursor: pointer;"  />
                                <br />
                                @:&nbsp;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         }
                            }
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
